﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator.Engine;
using EuroManager.Domain.Simulator.Helpers;
using NUnit.Framework;

namespace EuroManager.Domain.Simulator.Tests.Engine
{
    [TestFixture]
    public class MovingEntityTests
    {
        [Test]
        public void DirectionShouldBeParallelToVelocity()
        {
            TestMovingEntity entity = new TestMovingEntity();

            entity.Hit(new Vector2D(-3, 1));
            TestHelper.Advance(1, entity);

            Assert.IsTrue(entity.Direction.IsParallelWithSense(entity.Velocity));
        }

        [Test]
        public void ShouldBeMovingWhenVelocityIsNotZero()
        {
            TestMovingEntity entity = new TestMovingEntity();

            entity.Hit(Vector2D.UnitX);
            TestHelper.Advance(0.1f, entity);

            Assert.IsTrue(entity.IsMoving);
        }

        [Test]
        public void ShouldNotBeMovingWhenVelocityIsZero()
        {
            TestMovingEntity entity = new TestMovingEntity();
            TestHelper.Advance(0.1f, entity);

            Assert.IsFalse(entity.IsMoving);
        }

        [Test]
        public void ShouldMeasureDistanceToLocation()
        {
            TestMovingEntity entity = new TestMovingEntity(new Vector2D(10, 10));
            float distance = entity.DistanceTo(new Vector2D(13, 14));

            Assert.AreEqual(5, distance, Maths.Epsilon);
        }

        [Test]
        public void DirectionToLocationShouldBeParallelToTargetVector()
        {
            TestMovingEntity entity = new TestMovingEntity(new Vector2D(5, 3));
            
            Vector2D target = new Vector2D(15, 3);
            Vector2D direction = entity.DirectionTo(target);

            Assert.IsTrue(direction.IsParallelWithSense(target - entity.Location));
        }

        private class TestMovingEntity : MovingEntity
        {
            public TestMovingEntity()
                : this(Vector2D.Zero)
            {
            }

            public TestMovingEntity(Vector2D location)
                : base(location, 1, 1, 10)
            {
            }

            public new void Hit(Vector2D startVelocity)
            {
                base.Hit(startVelocity);
            }
        }
    }
}
